﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FCA.Dto {
    /// <summary>
    /// X = object = extent (tidset, number)
    /// </summary>
    public class TidSet {
        #region Properties
        /// <summary>
        /// X = object = extent (tidset, number)
        /// </summary>
        public HashSet<int> Tids { get; set; }
        #endregion

        #region Constructors
        public TidSet() {
            Tids = new HashSet<int>();
        }

        public TidSet(HashSet<int> tids)
            : this() {
                Tids = tids;
        }

        public TidSet(TidSet tids)
            : this() {
                foreach (int tid in tids.Tids) {
                    Tids.Add(tid);
            }
        }
        #endregion

        public void Add(int item) {
            Tids.Add(item);
        }

        public int Length() {
            return this.Tids.Count;
        }


        /// <summary>
        /// contains element existed in both of this & y 
        /// </summary>
        /// <param name="y"></param>
        /// <returns></returns>
        public TidSet IntersectWith(TidSet y) {
            TidSet res = new TidSet(y);
            res.Tids.IntersectWith(Tids);
            return res;
        }

        /// <summary>
        /// contains element existed in at least one of this & y (U)
        /// </summary>
        /// <param name="y"></param>
        /// <returns></returns>
        public TidSet UnionWith(TidSet y) {
            TidSet res = new TidSet(y);
            res.Tids.UnionWith(Tids);
            return res;
        }


        public string GetValueString() {
            return string.Join(",", Tids);
        }
    }
}
